#!/bin/sh

ftpServer=172.31.2.32
ftpUserName=siebel
ftpPassword=siebel
ftpRemoteDir="/app/siebel/siebsrvr/objects"
ftpLocalDir="/siebel/app/siebel/siebsrvr/objects"
logfile=/home/siebel/migrate/ftp.log
downfilesTemp=/home/siebel/migrate/transfer.ftp
currentDate=$(date +%Y%m%d)

echo 
echo "#-------------  Start Migrate Siebel DEV To Test At :`date +"%Y-%m-%d %H:%M:%S"` ----------#"


if [ ! -f "/siebel/app/siebel/siebsrvr/objects/chs/siebel_sia.srf.${currentDate}" ]
then
	# backup srf
	echo "# Backup SRF.... `date +"%Y-%m-%d %H:%M:%S"`"
	echo "#"
	
	cp /siebel/app/siebel/siebsrvr/objects/chs/siebel_sia.srf /siebel/app/siebel/siebsrvr/objects/chs/siebel_sia.srf.${currentDate}
	cp /siebel/app/siebel/siebsrvr/objects/enu/siebel_sia.srf /siebel/app/siebel/siebsrvr/objects/enu/siebel_sia.srf.${currentDate}
	
	echo "# Backup Completed! `date +"%Y-%m-%d %H:%M:%S"`"
	echo "#"

fi

lftp <<_LABEL
open $ftpServer
user $ftpUserName $ftpPassword
cd $ftpRemoteDir/chs/
lcd $ftpLocalDir/chs/
mget siebel_sia.srf
close
bye
_LABEL
echo "# CHS SRF Download Completed . `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

lftp <<_LABEL
open $ftpServer
user $ftpUserName $ftpPassword
cd $ftpRemoteDir/enu/ 
lcd $ftpLocalDir/enu/
mget siebel_sia.srf
close
bye
_LABEL

echo "# ENU SRF Download Completed . `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

# stop server
echo "# Restart Server `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"
/home/siebel/scripts/stopsrvr.sh

sleep 3

# start server 
/home/siebel/scripts/startsrvr.sh
echo "# Restart Server OK. `date +"%Y-%m-%d %H:%M:%S"`"
echo "#"

echo "#-------------  End   Migrate Siebel DEV To Test At :`date +"%Y-%m-%d %H:%M:%S"` ----------#"
echo 
